﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using InformationSystem.WebSite.Utility;
using InformationSystem.BLL.Core.Model;

namespace InformationSystem.WebSite
{
    public partial class UserOnline : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string result = "{0}success:true,count:{1}{2}";
            if (Session["LoginUser"] == null)
            {
                Response.Write(string.Format(result, "{", 0, "}"));
                Response.End();
            }
            else
            {
                List<LoginUser> useronlinelist = (List<LoginUser>)Application[Common.OnLine];
                LoginUser ui = useronlinelist.Find(val => val.UserID == ((LoginUser)Session["LoginUser"]).UserID);
                if (ui != null)
                {
                    Application.Lock();
                    ui.LastRefreshTime = DateTime.Now;
                    Application.UnLock();
                }

                int count = OnLineHandler.GetAllOnlineUserCount((List<LoginUser>)Application[Common.OnLine], (int)Application[Common.TimeOut]);
                Response.Write(string.Format(result, "{", count, "}"));
                Response.End();
            }
        }
    }
}